<template>
  <div class="contentShadow">
    <el-container>
      <el-header>
        <h1>联系方式</h1>
      </el-header>
      <el-main>
        <div>
          <el-form ref="form" :model="infoForm" :rules="rules" label-width="100px">
            <el-form-item label="学号" prop="username">
              <el-input v-model="infoForm.username" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="姓名" prop="name">
              <el-input v-model="infoForm.name" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="电话号码" prop="phone">
              <el-input v-model="infoForm.phone"></el-input>
            </el-form-item>
            <el-form-item label="电子邮箱" prop="email">
              <el-input v-model="infoForm.email"></el-input>
            </el-form-item>
            <el-form-item>

            </el-form-item>
          </el-form>
        </div>
        <div>
          <el-button type="primary" @click="submitForm" :loading="loading">提交</el-button>
          <el-button @click="resetForm">重置</el-button>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import {getStudentInformation} from "@/api/student"
import {changeContactInformation} from '@/api/student.js'
import {removeToken} from '@/utils/auth.js'

export default {
  name: "ChangePassword",
  data() {
    return {
      infoForm: {
        username: "",
        name: "",
        phone: "",
        email: "",
      },
      rules: {
        name: [{required: false, message: "请输入姓名", trigger: "blur"},],
        phone: [{required: false, message: "请输入电话号码", trigger: "blur"}],
        email: [{required: false, message: "请输入电子邮箱", trigger: "blur"}],
      },
      loading: false
    };
  },
  mounted() {
    getStudentInformation().then((res) => {
      // console.log(res)
      this.infoForm.username = res["data"]["studentId"];
      this.infoForm.name = res["data"]["name"];
      this.infoForm.phone = res["data"]["phoneNumber"];
      this.infoForm.email = res["data"]["email"];
    });
  },
  methods: {
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          console.log("敬请期待！")
/*          this.loading = true
          changeContactInformation(this.infoForm.name, this.infoForm.phone, this.infoForm.email).then(res => {
            if (res.code == 50003) {
              this.$message.error(res["msg"])
              this.loading = false
            } else {
              this.$message.success('信息修改成功')
              this.loading = false
            }
          }).catch(() => {
            // 修改失败，显示错误提示
            this.$message.error('信息修改失败')
            this.loading = false
          })
          // TODO: send user data to backend*/
        } else {
          console.log("form validation failed");
        }
      });
    },
    resetForm() {
      // this.$refs.form.resetFields();
      getStudentInformation().then((res) => {
        this.infoForm.username = res.data.studentId;
        this.infoForm.name = res.data.name;
        this.infoForm.phone = res.data.phoneNumber;
        this.infoForm.email = res.data.email;
      });
    },
  },
};
</script>

<style scoped>
.change {
  margin: 20px;
  padding: 20px;
  background-color: #ffffff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);

}
</style>
